#include <func.h>
void *thfunc(void *p)
{
    //ctime不是线程安全的接口
    time_t t;
    time(&t);
    char buf[26]={0};
    char* ptime=ctime_r(&t,buf);
    buf[24]='\0';
    printf("I am subthread! Time: %s\n",ptime);
    sleep(3);
    printf("I am subthread! Time: %s\n",ptime);
    pthread_exit(NULL);
}
int main(int argc,char *argv[])
{
    int ret;
    pthread_t pthid;
    long thret;
    ret=pthread_create(&pthid,NULL,thfunc,NULL);
    THREAD_ERROR_CHECK(ret,"pthread_create");
    sleep(1);
    time_t t;
    time(&t);
    char buf[26]={0};
    char* ptime=ctime_r(&t,buf);
    buf[24]='\0';
    printf("I am main thread! Time: %s\n",ptime);
    THREAD_ERROR_CHECK(ret,"pthread_cancel");
    pthread_join(pthid,(void**)&thret);
    THREAD_ERROR_CHECK(ret,"pthread_join");
    printf("retnum of subthread %ld\n",thret);
    return 0;
}

